<?php
require_once "SLogobanner.php";
require_once "SNews.php";
require_once "SPage.php";
require_once "SError.php";

class AboutPhotoController extends Zend_Controller_Action
{
	private $uiVar = array();
	private $sNews;
	private $sPage;

	
	public function init()
	{
		$this->uiVar["html"]["pageTitle"] = WEBSITE_TITLE;
		$this->sPage = new SPage();
		$this->sNews = new SNews();
	}

	public function photoAction()
	{
		$pageValues = array();
		$pageValues["html"]["title"] = WEBSITE_TITLE;
		$pageValues["data"]["selectedMenu"] = "about";
		$pageValues["data"]["selectedSubMenu"] = "picture";
		
		$language = (int)trim($this->_getParam("lang"));
		if ($language == 0) {
			$lang = 'vietnam';
			$language = 1;
		} else {
			$lang = 'china';
		}
		/*********************************************************************/
		$sLogoBanner = new SLogobanner();		
		$pageValues["data"]["leftBanner"]=$bannerLeft = $sLogoBanner->getBanner(1);
		$nameBanner1 = explode(".",$pageValues['data']['leftBanner']['ImagePath']);
		$pageValues["data"]["left_banner_name"] = $nameBanner1[0];

		
		
		$pageValues["data"]["headerBanner"]=$bannerLeft = $sLogoBanner->getBanner(2);
		$nameBanner2 = explode(".",$pageValues['data']['headerBanner']['ImagePath']);
		$pageValues["data"]["header_banner_name"] = $nameBanner2[0];
		
		
		$pageValues["data"]["centerBanner"]=$bannerLeft = $sLogoBanner->getBanner(3);
		$nameBanner3 = explode(".",$pageValues['data']['centerBanner']['ImagePath']);
		$pageValues["data"]["center_banner_name"] = $nameBanner3[0];
		/*********************************************************************/
		
		$pageValues["page"] = $this->sPage->getPage(1, $language);
		$pageValues["news"]["hot"] = $this->sNews->getNewsHotList($language, 0, HOMEPAGE_TOTAL_NEWS_PER_PAGE);
		
		$this->uiVar["pageValues"] = $pageValues;

		$smarty = Zend_Registry::get("SMARTY");
		$smarty->assign("uiVar", $this->uiVar);
		$smarty->display("about/photo_" . $lang . ".tpl");
	}
	
	public function listAlbumAction()
	{
		$db = Zend_Registry::get("DB");	
		$albumModel = new STE_Album($db);
		
		$params = $this->_getAllParams();
		$albums = $albumModel->getAlbumList($params['albumType'], $params['from'], $params['numberOfAlbums']);

		echo json_encode(array("code" => 0, "data" => $albums));
	}
	
	public function getAlbumCountAction()
	{
		$db = Zend_Registry::get("DB");	
		$albumModel = new STE_Album($db);
	
		$params = $this->_getAllParams();
		$r = $albumModel->getAlbumCountByAlbumType($params['albumType']);

		echo json_encode(array("code" => 0, "data" => $r["album_count"]));
	}

	public function listMediaAction()
	{
		$db = Zend_Registry::get("DB");	
		$photoModel = new STE_Photo($db);
		$videoModel = new STE_Video($db);
	
		$params = $this->_getAllParams();
		if($params['mediaType'] == 'photo') {
			$media = $photoModel->getPhotoList($params['albumID'], $params['from'], $params['numberOfMedia']);	
		} else {
			$media = $videoModel->getVideoList($params['albumID'], $params['from'], $params['numberOfMedia']);	
		}

		echo json_encode(array("code" => 0, "data" => $media));
	}
	
	public function getMediaCountAction()
	{
		$db = Zend_Registry::get("DB");	
		$photoModel = new STE_Photo($db);
		$videoModel = new STE_Video($db);
		
		$params = $this->_getAllParams();
		$params = $this->_getAllParams();
		if($params['mediaType'] == 'photo') {
			$r = $photoModel->getPhotoCountByAlbumType($params['albumID']);	
			echo json_encode(array("code" => 0, "data" => $r["photo_count"]));
		} else {
			$r = $videoModel->getVideoCountByAlbumType($params['albumID']);	
			echo json_encode(array("code" => 0, "data" => $r["video_count"]));
		}		
	}
}
?>